//written by Ray Zeller

#include "HTMLOutputter.h"
//#include "XMLPARSER.h"

#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>
#include <sstream>

using namespace std;

HTMLOutputter::HTMLOutputter()
{
}

void HTMLOutputter::StandardTable(vector<Event> testEvents){
	apps = testEvents;
	ofstream myfile ("example.html");
  	if (myfile.is_open())
  	{
    	 	myfile << 
"<TABLE BORDER CELLPADDING=2 CELLSPACING=3 WIDTH=520> \n" <<
"<TR> \n" <<
"  <TH><em>DAY!</em> \n";
for(int time = 0; time < 24; time++)
	{
		myfile<<
		makeRow(time);
	}
	myfile<<
	"<TH><small>All Day Event</small> \n";
	myfile<<
"</TR> \n" <<
"<TR> \n";
Processor p = Processor(testEvents);
vector< vector <string> > daysOutput = p.process();
int i = 0;
for (vector<vector< string> >::iterator it = daysOutput.begin(); it!=daysOutput.end(); ++it) {
	
	int j = 0;
	myfile<< "<TR>  <TD>" << p.getDays()[i] <<  "\n";
	for (vector< string> ::iterator daysIt= daysOutput[i].begin(); daysIt!=daysOutput[i].end(); ++daysIt){
		myfile<< "<TD><small>" + daysOutput[i][j] +  "</small> \n";
		j++;
	}
	i++;
}
	myfile<<
"</TABLE> \n";
myfile.close();}
 else cout << "Unable to open file";
}

string HTMLOutputter :: makeRow(int startTime){
	string s;
	stringstream time;
	stringstream endTime;
	time<<startTime;
	// use if (start > end) when working with doubles
	if(startTime!=23)
		endTime<<(startTime+1);
	else
		endTime<<0;
	s = "<TH><small>" + time.str() +":00 - " + endTime.str() + ":00</small> \n";
	return s;
}

HTMLOutputter::~HTMLOutputter()
{
}
